<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   zhaozilong
 * @Last Modified time: 2018-09-16 19:11:47
 */

namespace app\common\model;

class YoukuVideo extends BaseNew {
	// 设置数据表（不含前缀）
	protected $name = '';

	// 定义时间戳字段名
	protected $createTime = '';
	protected $updateTime = '';

	public function getListByIds($kids) {
		$map = array(
			'id'	=> array('in', implode(',', $kids)),
		);
		$data = $this->where($map)->select();
		$data = $data->toArray(); //转换为数组
		//print_r($this->getLastSql());
		return $this->parseSearch($data);
	}
	
	public function countSearch($map) {
		return $this->where($map)->count();
	}

	public function search($map, $limit) {
		$data = $this->where($map)->order('create_time desc')->limit($limit)->select();
		$data = $data->toArray(); //转换为数组
		return $this->parseSearch($data);
	}

	protected function parseSearch($data) {
		//$ftpWeb = config('app.ftp_web');
		$isopen_config = config('isopen_config');

		$list = array();
		foreach ($data as $key => $value) {
			//$value['picurl'] = $value['picurl'] ? $ftpWeb.$value['picurl'] : '';
			//$value['create_time'] = $value['create_time'] ? date("Y-m-d", $value['create_time']) : '';
			$value['status_show'] = isset($value['status']) ? $isopen_config[$value['status']] : '';

			$list[$value['id']] = $value;
			//print_r($list);exit;
			//$userIds[$value['user_id']] = $value['user_id'];
		}
		return array($list);
	}

	protected function parseInfo($info) {
		$ftpWeb = config('app.ftp_web');
		$isopen_config = config('isopen_config');

		//通用解析
		$info['create_time'] = date("Y-m-d H:i:s", $info['create_time']);
		$info['picurl'] = $info['picurl'] ? $ftpWeb.$info['picurl'] : '';
		//$info['status_show'] = $isopen_config[$info['status']];
		//通用解析

		return $info;
	}

}